package util;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class UtilCommon
{
    public static String getSerial(Date date, int index)
    {
        long msel = date.getTime();
        SimpleDateFormat fm = new SimpleDateFormat("MMddyyyyHHmmssSS");
        msel += index;
        date.setTime(msel);
        String serials = fm.format(date);
        return serials;
    }
    
    // ����Ƿ���ͼƬ��ʽ
    public static boolean checkIsImage(String imgStr)
    {
        boolean flag = false;
        if (imgStr != null)
        {
            if (imgStr.equalsIgnoreCase(".gif") || imgStr.equalsIgnoreCase(".jpg") || imgStr.equalsIgnoreCase(".jpeg")
                || imgStr.equalsIgnoreCase(".png"))
            {
                flag = true;
            }
        }
        return flag;
    }
    
    public static Date StrToDate(String str)
        throws ParseException
    {
        return new SimpleDateFormat("MM/dd/yyyy").parse(str);
    }
    
    /**
     * 将float格式化成两位小数
     * 
     * @param value
     * @return
     * @throws ParseException
     * @see [类、类#方法、类#成员]
     */
    public static Float formatFloat(Float value)
    {
        if (value == null)
        {
            return new BigDecimal(0).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
        }
        BigDecimal bigDecimal = new BigDecimal(value);
        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
    }
    
}